package com.zzc.controller;

import com.zzc.domain.User;
import com.zzc.service.impl.UserServiceImpl;
import com.zzc.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;


@Controller
public class LoginController {

    @Autowired
    private UserServiceImpl userService;

    @Autowired
    private MD5Util md5Util;

    @PostMapping("/login_a")
    public String loginAuthentication(String userAccount, String pwd, Model model){

        //登录验证
        User user = userService.loginAuthentication(userAccount);
        if (user == null||!md5Util.pwdToDbPwd(pwd, user.getSalt()).equals(user.getUserPwd())){
            model.addAttribute("msg","账号或密码错误！");
            return "login";
        }else{
            //model.addAttribute("msg","账号或密码错误！");
            return "index";
        }

    }

}
